package com.gljx.web.service.impl;

import com.gljx.web.Entity.Clazz;
import com.gljx.web.dao.ClazzMapper;
import com.gljx.web.dao.CommonDao;
import com.gljx.web.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class ClazzServiceImpl extends CommonDao implements ClazzService{

	@Autowired
	private ClazzMapper clazzMapper;
	
	/**
	 *取分页数据    dmz 20160921
	 *@param pindex 页码
	 *@param psql SQL语句，需要带 rownum rn 例如：select rownum rn,t.* from zzda t
	 *@param psize 每页记录数
	 * */
	@Override
	public Map<String, Object> selectPage(int pindex, String psql, int psize) {
		  Map<String, Object> paramMap = new HashMap<String, Object>();
	       paramMap.put("Pindex", pindex);
	       paramMap.put("Psql", psql);
	       paramMap.put("Psize", psize);
	       paramMap.put("Pcount", oracle.jdbc.OracleTypes.INTEGER);
	       paramMap.put("v_cur", oracle.jdbc.OracleTypes.CURSOR);
	       this.getSqlSession().select("com.gljx.web.dao.ClazzMapper.pagemap", paramMap, null);
	       return  paramMap;
	}

	/**
	 * 取记录总数      dmz 20160921
	 * @param psql   SQL语句
	 * @param pcount 记录总数
	 * @return
	 */
	@Override
	public Map<String, Object> selectPageCount(String psql) {
		   Map<String, Object> paramMap = new HashMap<String, Object>();
	       paramMap.put("Psql", psql);
	       paramMap.put("Pcount", oracle.jdbc.OracleTypes.INTEGER);
	       this.getSqlSession().select("com.gljx.web.dao.ClazzMapper.pagecount", paramMap, null);
	       return paramMap;
	}

	/**
	 * 实现根据条件查询
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Clazz> selectClazz(String companyId,String fid, String xqid, String clazzName) {
		// TODO Auto-generated method stub
		Map<String, Object>map = new HashMap<>();
		map.put("fid", fid);
		map.put("xqid", xqid);
		map.put("companyId", companyId);
		map.put("clazzName", clazzName);
		map.put("v_cursor", oracle.jdbc.OracleTypes.CURSOR);
		this.getSqlSession().select("com.gljx.web.dao.ClazzMapper.selectClazz", map, null); 
		return (List<Clazz>) map.get("v_cursor");
	}

	/**
	 * 实现获取编码方法
	 */
	@Override
	public String selectFnumber(String companyId) {
		// TODO Auto-generated method stub
		return clazzMapper.selectFnumber(companyId);
	}

	/**
	 * 实现添加方法
	 */
	@Override
	public void addClazz(Clazz clazz) {
		// TODO Auto-generated method stub
		clazzMapper.insertSelective(clazz);
	}

	/**
	 * 根据fid删除
	 */
	@Override
	public void deleteClazzByFid(String fid) {
		// TODO Auto-generated method stub
		clazzMapper.deleteByPrimaryKey(fid);
	}

	/**
	 * 实现根据fid修改
	 */
	@Override
	public void modifyClazz(Clazz clazz) {
		// TODO Auto-generated method stub
		clazzMapper.updateByPrimaryKeySelective(clazz);
	}
	
	/**
	 * 查询班级
	 * @createTime 2017-11-3 5:20 pm
	 * @author zyq.
	 */
	@Override
	public List<Clazz> selectClazzAll() {
		return clazzMapper.selectClazzAll();
	}

	@Override
	public List<Clazz> selectClazzByName(String name, String fcompanyid) {
		Map map = new HashMap();
			map.put("name",name);
			map.put("fcompanyid",fcompanyid);
		return clazzMapper.selectClazzByNameMap(map);
	}

/*	*//**
     * 根据名称模糊查询班级
     *//*
	@Override
	public List<Clazz> selectClazzByName(String name) {
		// TODO Auto-generated method stub
		return clazzMapper.selectClazzByName(name);
	}*/
	
	/**
	 * 根据ID查询班级
	 */
	@Override
	public Clazz selClazzById(String id) {
		// TODO Auto-generated method stub
		return clazzMapper.selClazzById(id);
	}

	@Override
	public List<Clazz> selectClazzExcel(String fnameL2, String fcompanyid) {
		Map<String, String> map = new HashMap<>();
		map.put("fnameL2",fnameL2);
		map.put("cfficompanyid",fcompanyid);
		return clazzMapper.selectClazzExcel(map);
	}

	@Override
	public List<Clazz> selectByCompanyID(String companyId) {
		
		return clazzMapper.selectByCompanyID(companyId);
	}
}
